#include "include/Player.h"

Player::Player(std::string m_Name, int m_Order) noexcept
	: m_Name(m_Name)
	, m_Order(m_Order) {}

int Player::getOrder() noexcept {
	return this->m_Order;
}

void Player::setOrder(int m_Order) noexcept {
	this->m_Order = m_Order;
}

std::string Player::getName() noexcept {
	return this->m_Name;
}

bool Player::operator==(Player player) noexcept {
	if (this->m_Order == player.m_Order)
		return true;
	return false;
}

Team::Team(int teamMemberNum, int teamID, std::string m_TeamName) noexcept
	: m_MemberNum(teamMemberNum)
	, m_Id(teamID)
	, m_TeamName(m_TeamName) {
	this->m_Members.resize(teamMemberNum);
	for (auto &i : this->m_Members)
		i = new Player(nullPlayer);
}

Team::~Team() noexcept {
	for (auto &i : this->m_Members)
		delete i;
}

void Team::join(Player player, int pos) noexcept(false) {
	if (*this->m_Members[pos] != nullPlayer)
		*this->m_Members[pos] = player;
}

void Team::kick(Player player) noexcept(false) {
	for (auto &i : this->m_Members)
		if (*i == player)
			*i = nullPlayer;
}

std::vector<Player *> Team::listPlayer() {
	return this->m_Members;
}

void move(Team *__restrict dst,
		  Team *__restrict src,
		  Player player,
		  int posDst) noexcept(false) {
	dst->join(player, posDst);
	src->kick(player);
}
